package com.example.definedview;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;

import com.example.definedview.databinding.ActivityScheduleBinding;
import com.example.definedview.view.MyAdapter;
import com.example.definedview.view.bean.ScheduleBean;

import java.util.ArrayList;
import java.util.List;

public class ScheduleActivity extends AppCompatActivity {
    ActivityScheduleBinding activityScheduleBinding;
    List<ScheduleBean> scheduleBeanList = new ArrayList<>();
    MyAdapter myAdapter;
    int count = 0;

    //当前进度
    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_schedule);
        activityScheduleBinding = DataBindingUtil.setContentView(this, R.layout.activity_schedule);
        scheduleBeanList.add(new ScheduleBean(R.drawable.beng, R.drawable.stateoff, "开始进样，这一步是将自来水从管道中抽取至储水桶中。"));
        scheduleBeanList.add(new ScheduleBean(R.drawable.jingzhi, R.drawable.stateoff, "静置，使杂质沉淀。"));
        scheduleBeanList.add(new ScheduleBean(R.drawable.beng, R.drawable.stateoff, "抽取待测水样至反应室"));
        scheduleBeanList.add(new ScheduleBean(R.drawable.zu, R.drawable.stateoff, "测量背景光谱"));
        scheduleBeanList.add(new ScheduleBean(R.drawable.suanjiandu, R.drawable.stateoff, "调节PH值，进行后续测量，PH的值会对光谱产生影响，所以PH的测量必须精确"));
        scheduleBeanList.add(new ScheduleBean(R.drawable.zu, R.drawable.stateoff, "测量调节PH值后的光谱光谱"));
        scheduleBeanList.add(new ScheduleBean(R.drawable.wushuibeng, R.drawable.stateoff, "排出废水"));

        myAdapter = new MyAdapter();
        myAdapter.setScheduleBeanList(scheduleBeanList);
        myAdapter.notifyDataSetChanged();

        activityScheduleBinding.recycleView.setLayoutManager(new LinearLayoutManager(this));
        activityScheduleBinding.recycleView.setAdapter(myAdapter);


        activityScheduleBinding.pre.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(count > 0){
                    count--;
                    scheduleBeanList.get(count).setState(R.drawable.stateoff);

                    myAdapter.setScheduleBeanList(scheduleBeanList);
                    myAdapter.notifyDataSetChanged();
                }
            }
        });
        activityScheduleBinding.after.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(count < scheduleBeanList.size()){
                    scheduleBeanList.get(count).setState(R.drawable.stateon);
                    count++;
                    myAdapter.setScheduleBeanList(scheduleBeanList);
                    myAdapter.notifyDataSetChanged();
                }
            }
        });
    }
}
